<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"
      xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<head>
  <title>Ubiquity Web Search Commands for Japanese, nora - jgfeelinglucky</title>
</head>
<body>
<p>This xhtml source contains commands for searching the Web.  Its
corresponding feed is <a href="ubiquity-commands-ja-nora-jgfeelinglucky.html">here</a>.</p>


<div id="jgfeelinglucky" style="display: none;">
<div class="title"><b>${query}</b>で Google I'm feeling lucky: <br/>
<a href="${url}" class="forward" style="font-size:small;font-weight:bold;">${url}</a></div>
<!--img src="http://open.thumbshots.org/image.aspx?url=${url}" width="240" style="margin:10px;" /-->
<img src="http://capture.heartrails.com/400x400/cool/shorten/bg=333333?${url}" style="margin:10px;" />
<div class="thumbservicecaption" style="font-size:x-small;"><a href="http://capture.heartrails.com/">HeartRails Capture | サムネイル画像／PDF ファイル作成サービス を利用しています。</a></div>
</div>
<div id="jgfeelinglucky_progress" style="display: none;">
<div class="title"><b>${query}</b>で Google I'm feeling lucky: </div>
<img src="http://ubiquity-commands-ja-nora.googlecode.com/files/image_7990.gif" style="display:none;position:absolute;top:40%;left:40%;" class="progressimage" id="progress" />
</div>


<script class="commands"><![CDATA[

CmdUtils.CreateCommand({
    name: "jgfeelinglucky",
    description: "www.google.co.jp",
    takes: {search: noun_arb_text},
    icon: "http://www.google.co.jp/favicon.ico",
	homepage: "http://code.google.com/p/ubiquity-commands-ja-nora/",
	author: {name: "hokunarin", email: "hokunarin@gmail.com"},
	license: "MPL",

    preview: function( previewBlock, directObject ) {
        
        var DBG = true;
        
        function dbg(string){
            if(DBG) Utils.reportInfo(string);
        }
        
        var searchText = jQuery.trim(directObject.text);
        if(searchText.length < 1) {
            var previewStr = "Google.co.jp - I'm feeling Lucky ";
            previewBlock.innerHTML = previewStr;
            return;
        }
        
        previewBlock.innerHTML = CmdUtils.renderTemplate(jQuery("#jgfeelinglucky_progress", feed.dom).html(), {query: searchText});
        jQuery("#progress",previewBlock).hide().fadeIn(750);
        
        var urlString = "http://www.google.co.jp/search";
        
        var paramData = { 
                         hl : "ja",
                         q : searchText,
                         btnI : "I'm Feeling Lucky",
                         lr : "",
                         aq : "f",
                         oq : ""
                         };
        paramData = Utils.paramsToString(paramData);
        
        urlString += paramData;
        
        dbg(urlString);
        
        
        CmdUtils.previewAjax(previewBlock, {
            
            url : urlString,
            async:true,
            
            beforeSend: function(xhr){
                xhr.setRequestHeader("Referer", "http://www.google.co.jp"); 
            },
            
            complete: function(xhr, status){
                
                var location = xhr.channel.URI.spec;
                dbg(location);
                
                
                previewBlock.innerHTML = CmdUtils.renderTemplate( jQuery("#jgfeelinglucky", feed.dom).html(), {url:location, query:searchText });
                
            },
            
            success: function(data, dataType){
                
            },
            
            error: function(){
                
            }
        });
        
    },

    execute: function( directObject ) {
        var urlString = "http://www.google.co.jp/search";
        //Utils.openUrlInBrowser(urlString + "?" + "hl=ja&btnI=I'm+Feeling+Lucky&q=" + encodeURI(directObject.text));
        
        var paramData = { 
                         hl : "ja",
                         q : directObject.text,
                         btnI : "I'm Feeling Lucky",
                         lr : "",
                         aq : "f",
                         oq : ""
                         };
        paramData = Utils.paramsToString(paramData);
        
        //Utils.openUrlInBrowser( urlString + paramData );
        
        
        urlString += paramData;
        
        var referrerURL = "http://www.google.co.jp";
        
        var postInputStream = null;
        
        var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
        var referrerURI = ioService.newURI(referrerURL, null, null);
       
        var browserWindow = Utils.currentChromeWindow;
        var browser = browserWindow.getBrowser();
        
        var referrer = ioService.newURI(referrerURL, null, null);
        
        var prefService = Cc["@mozilla.org/preferences-service;1"] .getService(Ci.nsIPrefBranch); 
        var openPref = prefService.getIntPref("browser.link.open_newwindow"); 
        
        if(browser.mCurrentBrowser.currentURI.spec == "about:blank" &&  !browser.webProgress.isLoadingDocument ) 
            browserWindow.loadURI(urlString, referrer, postInputStream, false); 
        else if(openPref == 3) 
            browser.loadOneTab(urlString, referrer, null, postInputStream, false, false); 
        else if(openPref == 2) 
            browserWindow.openDialog('chrome://browser/content', '_blank', 'all,dialog=no', urlString, null, referrer, postInputStream);
        else 
            browserWindow.loadURI(urlString, referrer, postInputStream, false); 
        
        
    }
    
    
});


]]></script>
</body>
</html>
